<template>
    <!-- 商品修改页 -->
    <div>
        <el-card class="box-card">
            <el-form :model="formData" label-position="left" label-width="100px" size="medium" @submit.native.prevent>
                <div class="static-content-item">
                    <div>修改</div>
                </div>
                <div class="static-content-item">
                    <el-divider direction="horizontal"></el-divider>
                </div>
                <el-row style="margin-top: 20px;">
                    <el-col :span="12" class="grid-cell">
                        <el-form-item label="货物编号" prop="item_code" class="required label-center-align">
                            <el-input v-model="formData.item_code"  style="width: 300px;"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" class="grid-cell">
                        <el-form-item label="货物名称" prop="item_name" class="required label-center-align">
                            <el-input v-model="formData.item_name" type="text" style="width: 300px;"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" class="grid-cell">
                        <el-form-item label="状态" prop="inbill_state" class="required label-center-align">
                            <el-input v-model="formData.inbill_state" type="text" style="width: 300px;"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" class="grid-cell">
                        <el-form-item label="货物类型" prop="item_type" class="required label-center-align">
                            <el-input v-model="formData.item_type" type="text" style="width: 300px;"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" class="grid-cell">
                        <el-form-item label="类型编号" prop="item_type_code" class="required label-center-align">
                            <el-input v-model="formData.item_type_code" type="text" style="width: 300px;"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" class="grid-cell">
                        <el-form-item label="规格型号" prop="model_code" class="required label-center-align">
                            <el-input v-model="formData.model_code" type="text" style="width: 300px;"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" class="grid-cell">
                        <el-form-item label="单位" prop="unit" class="required label-center-align">
                            <el-input v-model="formData.unit" type="text" style="width: 300px;"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" class="grid-cell">
                        <el-form-item label="货品上限" prop="item_up" class="required label-center-align">
                            <el-input v-model="formData.item_up" type="text" style="width: 300px;"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" class="grid-cell">
                        <el-form-item label="货品下限" prop="item_down" class="required label-center-align">
                            <el-input v-model="formData.item_down" type="text" style="width: 300px;"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" class="grid-cell">
                        <el-form-item label="低于下限" prop="below_down" class="required label-center-align">
                            <el-input v-model="formData.below_down" type="text" style="width: 300px;"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" class="grid-cell">
                        <el-form-item label="高于下限" prop="above_up" class="required label-center-align">
                            <el-input v-model="formData.above_up" type="text" style="width: 300px;"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" class="grid-cell">
                        <el-form-item label="入库参考价" prop="inbill_price" class="required label-center-align">
                            <el-input v-model="formData.inbill_price" type="text" style="width: 300px;"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" class="grid-cell">
                        <el-form-item label="出库参考价" prop="outbill_price" class="required label-center-align">
                            <el-input v-model="formData.outbill_price" type="text" style="width: 300px;"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" class="grid-cell">
                        <el-form-item label="排序" prop="sort_code" class="required label-center-align">
                            <el-input v-model="formData.sort_code" type="text" style="width: 300px;"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </el-card>
       
        <div class="footer-nav">
            <el-row style="float: right;">
                <!-- 底部导航栏内容 -->
                <router-link to="Product information">
                    <el-button size="small">关闭</el-button>
                </router-link>
                <el-button size="small" @click="AddSupplier()">保存并新增</el-button>
                <el-button size="small" @click="xg()" type="primary">保存</el-button>
            </el-row>
        </div>
    </div>
</template>
<script>
import $http from '../http/base.js'
export default {
    components: {},
    props: {},
    data() {
        return {
            formData: {
                id:"",
                item_code: "",
                item_type_code: "",
                item_name: "",
                item_type: "",
                sort_code: '',
                inbill_state: '',
                model_code: "",
                outbill_price: "",
                inbill_price: "",
                item_up: '',
                item_down: '',
                below_down: "",
                above_up: "",
                unit: "",
                is_del: 0
            },
            value1: '',
            value2: '',
        }
    },
    computed: {},
    watch: {},
    created() { },
    mounted: function () {
        this.RandomID()
        this.Itemselectid()
    },
    methods: {
        //生成随机供应商编码
        RandomID() {
            // 定义一个函数生成编码
            function generateCode() {
                const date = new Date();
                const year = date.getFullYear();
                const month = (date.getMonth() + 1).toString().padStart(2, '0');
                const day = date.getDate().toString().padStart(2, '0');
                const hours = date.getHours().toString().padStart(2, '0');
                const minutes = date.getMinutes().toString().padStart(2, '0');
                const seconds = date.getSeconds().toString().padStart(2, '0');
                const fixedLetters = 'PF';
                return fixedLetters + year + month + day + hours + minutes + seconds;
            }
            // 使用函数生成编码
            const randomCode = generateCode();
            console.log(randomCode); // 示例打印：20231129113510Y
            this.formData.item_code = randomCode
        },
        xg() {
            $http.post('https://localhost:7020/api/BsItem/ItemUpdate', this.formData
            ).then(res => {
                    if (res.data != "") {
                        alert("修改成功！");
                        console.log("修改成功" + res);
                        this.$router.push('BsItem');
  
                    }
                }).catch(err => {
                    alert("修改失败！")
                    console.log(err);
                })
        },Itemselectid(){
            $http.get('https://localhost:7020/api/BsItem/ItemSelectid?id=' + this.$route.params.id)
                .then(res => {
                    console.log(res)
                    this.formData.id=res.id;
                    this.formData.item_code=res.item_code;
                    this.formData.item_type_code=res.item_type_code;
                    this.formData.item_name=res.item_name;
                    this.formData.item_type=res.item_type;
                    this.formData.sort_code=res.sort_code;
                    this.formData.inbill_state=res.inbill_state;
                    this.formData.model_code=res.model_code;
                    this.formData.outbill_price=res.outbill_price;
                    this.formData.inbill_price=res.inbill_price;
                    this.formData.item_up=res.item_up;
                    this.formData.item_down=res.item_down;
                    this.formData.below_down=res.below_down;
                    this.formData.above_up=res.above_up;
                    this.formData.unit=res.unit;
                    this.formData.is_del=res.is_del;
                })
        }
    }
}
</script>
<style scoped>
.footer-nav {
    position: fixed;
    bottom: 0;
    right: 0px;
    height: 40px;
    background-color: #f0f0f0;
    display: flex;
    justify-content: space-around;
    align-items: center;
    width: 1720px;
    float: right;
}

.footer-nav a {
    color: #333;
    text-decoration: none;
    font-size: 16px;
}

.footer-nav a:hover {
    color: #000;
}

.text {
    font-size: 14px;
}

.item {
    padding: 18px 0;
}

.box-card {
    width: 1500px;
    margin: auto;
}
</style> 
<style>
.el-input-number.full-width-input,
.el-cascader.full-width-input {
    width: 100% !important;
}

.el-form-item--medium {
    .el-radio {
        line-height: 36px !important;
    }

    .el-rate {
        margin-top: 8px;
    }
}

.el-form-item--small {
    .el-radio {
        line-height: 32px !important;
    }

    .el-rate {
        margin-top: 6px;
    }
}

.el-form-item--mini {
    .el-radio {
        line-height: 28px !important;
    }

    .el-rate {
        margin-top: 4px;
    }
}

.clear-fix:before,
.clear-fix:after {
    display: table;
    content: "";
}

.clear-fix:after {
    clear: both;
}

.float-right {
    float: right;
}
</style>

<style scoped>
div.table-container {
    table.table-layout {
        width: 100%;
        table-layout: fixed;
        border-collapse: collapse;

        td.table-cell {
            display: table-cell;
            height: 36px;
            border: 1px solid #e1e2e3;
        }
    }
}

.label-left-align ::v-deep .el-form-item__label {
    text-align: left;
}

.label-center-align ::v-deep .el-form-item__label {
    text-align: center;
}

.label-right-align ::v-deep .el-form-item__label {
    text-align: right;
}

.static-content-item {
    min-height: 20px;
    display: flex;
    align-items: center;

    ::v-deep .el-divider--horizontal {
        margin: 0;
    }
}
</style>